package com.yihu.cms.action;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.beans.Users;
import com.yihu.beans.tags.Tags;
import com.yihu.cms.service.TagsManagerService;

@Controller
public class TagsManagerController extends BaseController {
	
	protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	TagsManagerService ts = new TagsManagerService();
	
	@RequestMapping(value = "/tagsmanger/list", method = RequestMethod.GET)
	public @ResponseBody Object getTagsList(String userName)
	{
		log.info("tagsmanger list . user=" + userName);
		return ts.getList(userName);
	}
	
	@RequestMapping(value = "/tagsmanger", method = RequestMethod.POST)
	public @ResponseBody Object tagCreate(@RequestBody Tags tag) {
		log.info("createt tagsmanger userName=" +tag );

		int result = ts.add(tag);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
	@RequestMapping(value = "/tagsmanger", method = RequestMethod.DELETE)
	public @ResponseBody Object tagDel(
			@RequestParam(value="id",required=false , defaultValue = "0")Long id) {
		int result = ts.del(id);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
	@RequestMapping(value = "/tagsmanger", method = RequestMethod.PUT)
	public @ResponseBody Object tagUpdate(@RequestBody Tags tag) {
		int result = ts.update(tag);
		log.info("result=" + result);
		return getResult(result, null);
	}
	
	@RequestMapping(value = "/tagsmanger/{id:\\d+}", method = RequestMethod.GET)
	public @ResponseBody Tags getTag(@PathVariable("id") Long id) {
		log.info("get tagsmanger id=" + id);
//		Tags tag = ts.getTagById(id);
		return ts.getTagById(id);
	}

}
